
# 字符串的CRUD操作

# 字符串的增加
a = "abcdefg"
b = "ABC"
a = a+b
print(a)
a = "abcdefg"
a += b
print(a)

# 字符串的检索
A = "abcdefg"
c = A.find('b')
print(c)
c = A.index('c')
print(c)
c = A.startswith('a')
print(c)
c = A.endswith('g')
print(c)
print(A[2:4])   # 索引

# 字符串的更新
m = "hhhgggg"
m.replace("h", "z")
print(m)
m = m.replace("h", "z")
print(m)

# 字符串的分割和合并
date_str = "2020-12-23 20:00"
my_ruslt = date_str.split(" ")
print(my_ruslt)
tmp = " ".join(my_ruslt)
print(tmp)

# 字符串的删除
a = " 好开心 "
b = a.strip(" ")
print(b)
a = "我好开心啊"
b = a.lstrip("我")
print(b)
b = a.rstrip("啊")
print(b)

# 字符串的格式化
city = "shenzhen"
b = "guangdong-{}-{}".format(city, "baoan")
print(b)

b = "{0}, {1}, {0}, {1}".format("wa", "ha")
print(b)

d = f"{city}-linfeng"
print(d)

c = 3.123456
b = "{:.3f}".format(c)
print(b)



